﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Web.UI.HtmlControls;
using System.Web.UI;
using System.Web;
using System.Net;


using DevExpress.Web.ASPxHeadline;

using LMD.Lib.DataClass;
using LMD.Constant;
using LMD.Lib.Interface;
using LMD.Lib.Oracle;
using LMD.Lib.Controls;

/// <summary>
/// Summary description for CARManager
/// </summary>
public static class CARManager
{
    public static String BuildEditor_SPOC()
    {
        String sxOutput = String.Empty;
        String sxOTFComboCAR = CustomControls.Create_OTFComboBox(
            KCARSpoc.CARID, KLOV.Generic.ICPCAR, null, null, TextboxType.Empty, String.Empty, "SelectCAR()");
        Dictionary<String, String> dicSort = new Dictionary<String, String>();
        dicSort.Add("ASCENDING", "ASCENDING");
        dicSort.Add("DESCENDING", "DESCENDING");
        String sxComboSort = CustomControls.Create_ComboBox(KCARSpoc.SORT, KControl.INPUT_ID, dicSort, "ASCENDING");

        sxOutput += CustomControls.BuildFieldSet_PairedLabel("CAR", sxOTFComboCAR);
        sxOutput +=
            "<dt>&nbsp;</dt><dd><input type=\"button\" id=\"btnAll\" class=\"btn\" " +
            "style=\"margin-left: 5px; margin-right: 5px; width:100px;\"" +
                "onclick=\"All();\" value=\"Show All\" /> "+
            "<div id=\"load\" style=\"float: left; margin-left: 5px; margin-right: 5px;\"></div></dd>";
        //sxOutput += CustomControls.BuildFieldSet_PairedLabel("TOTAL REVENUE Sort By", sxComboSort);
        sxOutput +=
            "<dt>Revenue Sort</dt><dd><input type=\"button\" id=\"btnSort\" class=\"btn\" " +
            "style=\"margin-left: 5px; margin-right: 5px; width:100px;\"" +
                "onclick=\"Sort();\" value=\"Descending\" /></dd> ";
        sxOutput += "<input type=\"hidden\" id=\"hfSort\"/>";
        return sxOutput;
    }
    public static String BuildEditor_CARByCAR()
    {
        String sxOutput = String.Empty;
        String sxOTFComboCAR = CustomControls.Create_OTFComboBox(
            KCARSpoc.OLDCARID, KLOV.Generic.ICPCAR, null, null, TextboxType.Empty, String.Empty, "SelectCAR()");

        sxOutput += CustomControls.BuildFieldSet_PairedLabel("Recent CAR", sxOTFComboCAR);

        return sxOutput;
    }
    public static String BuildEditor_CARByCARNew()
    {
        String sxOutput = String.Empty;
        String sxOTFComboCAR = CustomControls.Create_OTFComboBox(
            KCARSpoc.CARID, KLOV.Generic.ICPCAR, null, null, TextboxType.Empty);

        sxOutput += CustomControls.BuildFieldSet_PairedLabel("New CAR", sxOTFComboCAR);
        sxOutput +=
            "<dt>&nbsp;</dt><dd><input type=\"button\" id=\"btnChange\" class=\"btn\"" +
            "style=\"margin-left: 5px; margin-right: 5px; width:100px;\"" +
                "onclick=\"Change();\" value=\"CHANGE\" /> " +
            "<div id=\"load\" style=\"float: left; margin-left: 5px; margin-right: 5px;\"></div></dd>";

        return sxOutput;
    }
    public static String BuildEditor_CARByCompany()
    {
        String sxOutput = String.Empty;

        String sxOTFComboCustomer = CustomControls.Create_OTFComboBox(
            KCARSpoc.CUSTOMERID, KLOV.CourtesyCall.COMPANYLIST, null, null, TextboxType.Empty, String.Empty, "SelectCompany()");
        String sxOTFCAR = CustomControls.Create_OTFComboBox(KCARSpoc.CARID,
            KLOV.Generic.ICPCAR, "", "", TextboxType.Empty, String.Empty, String.Empty);

        sxOutput += CustomControls.BuildFieldSet_PairedLabel("Company Name", sxOTFComboCustomer);
        sxOutput += CustomControls.BuildEditor_LabelAndText(KCARSpoc.OLDCARID, KControl.INPUT_ID, "Recent CAR", null, TextboxType.ReadOnly);
        sxOutput += CustomControls.BuildFieldSet_PairedLabel("New CAR", sxOTFCAR);
        sxOutput +=
            "<dt>&nbsp;</dt><dd><input type=\"button\" id=\"btnChange\" class=\"btn\"" +
            "style=\"margin-left: 5px; margin-right: 5px; width:100px;\"" +
                "onclick=\"Change();\" value=\"CHANGE\" /> " +
            "<div id=\"load\" style=\"float: left; margin-left: 5px; margin-right: 5px;\"></div></dd>";
        return sxOutput;
    }
    public static String BuildEditor_AvailabilityFilter()
    {
        String sxOutput = String.Empty;

        //String sxOTFComboCustomer = CustomControls.Create_OTFComboBox(
        //    KCARSpoc.CUSTOMERID, KLOV.CourtesyCall.COMPANYLIST, null, null, TextboxType.Empty, String.Empty, "SelectCompany()");
        //String sxOTFCAR = CustomControls.Create_OTFComboBox(KCARSpoc.CARID,
        //    KLOV.Generic.ICPCAR, "", "", TextboxType.Empty, "-1", String.Empty);

        String sxOTFComboCustomer = CustomControls.Create_OTFComboBox(
            KCARSpoc.CUSTOMERID, KLOV.CourtesyCall.COMPANYLIST, null, null, TextboxType.Empty, "-1", String.Empty);
        String sxOTFCAR = CustomControls.Create_OTFComboBox(KCARSpoc.CARID,
            KLOV.Generic.ICPCAR, null, null, TextboxType.Empty, String.Empty, "SelectCAR()");

        sxOutput += CustomControls.BuildFieldSet_PairedLabel("CAR", sxOTFCAR);
        sxOutput += CustomControls.BuildFieldSet_PairedLabel("Company Name", sxOTFComboCustomer);
        sxOutput += 
            "<dt>&nbsp;</dt><dd><input type=\"button\" id=\"btnFilter\" class=\"btn\"" +
            "style=\"margin-left: 5px; margin-right: 5px; width:100px;\"" +
                "onclick=\"Filter();\" value=\"FILTER\" /></dd> " +
            "<div id=\"load\" style=\"float: right; margin-left: 5px; margin-right: 5px;\"></div>";
        return sxOutput;
    }

    public static String BuildNav()
    {
        String sxOutput = String.Empty;
        sxOutput = 
        "<input type=\"button\" id=\"btnNext\" class=\"btn\""+ 
        "   style=\"display: inline; float: right; margin-left: 5px; margin-right: 5px; width:45px;\""+
        "   onclick=\"Reload('NEXT');\" value=\"NEXT\" />"+
        "<input type=\"button\" id=\"btnPrev\" class=\"btn\""+ 
        "   style=\"display: inline; float: right; margin-left: 5px; margin-right: 5px; width:85px;\""+
        "   onclick=\"Reload('PREV');\" value=\"PREVIOUS\" />";

        return sxOutput;
    }
    public static String BuildEditor_PopUp(String sxControlId, DataTable dt)
    {
        String sxOutput = String.Empty;

        String sxDef = String.Empty;
        String sxLink = String.Empty;
        DateTime dtmVisitDateTime = DateTime.Now;
        foreach (DataRow dr in dt.Rows)
        {
            sxLink = String.Format(
                "<a class=\"lnk\" href=\"CompanyProfile.aspx?cid={0}\" alt=\"{1}\">{1}</a>",
                dr["CUSTOMER_ID"].ToString(),
                dr["COMPANY_NAME"].ToString());
            sxDef += CustomControls.BuildFieldSet_PairedLabel("Company", sxLink);
            sxDef += CustomControls.BuildFieldSet_PairedLabel("Contact Person", dr["CONTACT_NAME"].ToString());
            dtmVisitDateTime = Convert.ToDateTime(dr["VISIT_DATETIME"]);
            sxDef += CustomControls.BuildFieldSet_PairedLabel("Visit Date Time", dtmVisitDateTime.ToString("dd MMMM yyyy, H:mm:ss"));
            sxDef += CustomControls.BuildFieldSet_PairedLabel("Visit Purpose", dr["VISIT_PURPOSE"].ToString());
            sxDef += "<dt>&nbsp;</dt><dd>&nbsp;</dd>";
        }

        sxOutput = String.Format(
            "<div id=\"{1}_{0}\" class=\"popLOV\">" +
                "<fieldset class=\"m_fs_border\" id=\fs_lov_{0}\">" +
                    "<legend>" +
                        "<a class=\"lnk\" href=\"javascript:toggle('lov_{0}');\">CAR Customer Visit Position</a>" +
                    "</legend>" +
                    "<dl class=\"m_fs\"><div id=\"div_invite_{0}\">{2}</div></dl>" +
                    "<div id=\"load\" style=\"float: right; padding-right: 10px;\"></div>" +
                    "<input type=\"button\" id=\"btnCancel_lov_{0}\" class=\"btn\" style=\"float: right; margin-left: 5px; margin-right: 15px;\"" +
                        " onclick=\"ClosePopUp();\" value=\"close\" />" +
                "</fieldset>" +
            "</div>",
            sxControlId,
            KControl.GENERICPOPFORM_ID,
            sxDef
            );
        return sxOutput;
    }
}
